home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / fpu881 / src6.zoo / poly.c < prev    next >
C/C++ Source or Header  |  1991-09-24  |  2KB  |  92 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FUNCTION
  23.  *
  24.  *    poly   double precision polynomial evaluation
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    poly
  29.  *    machine independent routines
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Evaluates a polynomial and returns double precision
  35.  *    result.  Is passed a the order of the polynomial,
  36.  *    a pointer to an array of double precision polynomial
  37.  *    coefficients (in ascending order), and the independent
  38.  *    variable.
  39.  *
  40.  *  USAGE
  41.  *
  42.  *    double poly (order, coeffs, x)
  43.  *    int order;
  44.  *    double *coeffs;
  45.  *    double x;
  46.  *
  47.  *  PROGRAMMER
  48.  *
  49.  *    Fred Fish
  50.  *
  51.  *  INTERNALS
  52.  *
  53.  *    Evalates the polynomial using recursion and the form:
  54.  *
  55.  *        P(x) = P0 + x(P1 + x(P2 +...x(Pn)))
  56.  *
  57.  */
  58.  
  59. #include <stdio.h>
  60. #include <pmluser.h>
  61. #include "pml.h"
  62.  
  63.  
  64. double poly (order, coeffs, x)
  65. register int order;
  66. double *coeffs;
  67. double x;
  68. {
  69.     auto double curr_coeff;
  70.     auto double rtn_value;
  71.  
  72.     DBUG_ENTER ("poly");
  73.     DBUG_5 ("polyin", "args %d %#x %le", order, coeffs, x);
  74. #if 0
  75.     if (order <= 0) {
  76.     rtn_value = *coeffs;
  77.     } else {
  78.     curr_coeff = *coeffs;    /* Bug in Unisoft's compiler.  Does not */
  79.     coeffs++;        /* generate good code for *coeffs++ */
  80.     rtn_value = curr_coeff + x * poly (--order, coeffs, x);
  81.     }
  82. #else /* ++jrb -- removed tail recursion */
  83.     coeffs += order;
  84.     rtn_value = *coeffs--;
  85.     while(order-- > 0)
  86.     rtn_value = *coeffs-- + (x * rtn_value);
  87.  
  88. #endif
  89.     DBUG_3 ("polyout", "result %le", rtn_value);
  90.     DBUG_RETURN (rtn_value);
  91. }
  92.